#include <cstdio>
#include <cstring>
#include <iostream> 
#include <algorithm>
#include <map>
#include <set>
using namespace std;
map<int,int>mp;
set<int>s0,s1,s2;
const int maxn = 1100;
int a[maxn];
int b[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		for(int i = 0;i<n;i++)
		{
			scanf("%d",&a[i]);
			b[i] = a[i];
			s0.insert(a[i]);
		}
		
		int ans=-1;
		for(int i=1;i<=2000;i++){
			s2=s0;
			for(int j = 0;j<n;j++)
			{
				b[j] = (a[j]^i);
				s1.insert(b[j]);
			}
			for(int j = 0;j<n;j++)
			{
				s2.erase(b[j]);
			}
			if(s2.size()==0)
			{
				ans=i;
				s2.clear();
				break;
			}
			s2.clear();
		}
		s0.clear();
		s1.clear();
		s2.clear();
		printf("%d\n",ans);
	}
	return 0;
}

